#!/usr/bin/env python
# _*_coding:utf-8 _*_
__author__ = "Gao"
from django import template
from crm import models
from django.db.models import Sum
register = template.Library()


@register.simple_tag
def get_total_score(enroll_obj):
    '''获取总成绩'''
    study_records = enroll_obj.studyrecord_set.filter(
        # course_record__from_class_id=enroll_obj.enrolled_class.id
    )
    res = study_records.aggregate(total=Sum('score'))
    return res['total']